package com.beemans.common.ui.views

import androidx.annotation.ColorRes
import com.beemans.common.R
import com.beemans.common.ext.toColor
import com.blankj.utilcode.util.Utils
import com.yanyusong.y_divideritemdecoration.Y_Divider
import com.yanyusong.y_divideritemdecoration.Y_DividerBuilder
import com.yanyusong.y_divideritemdecoration.Y_DividerItemDecoration

/**
 * @author tiamosu
 * @date 2021/3/15
 *
 * 描述：RecyclerView 分割线配置
 */
open class CustomDivider(
    protected var widthDp: Float = 0f,
    @ColorRes color: Int = R.color.transparent
) : Y_DividerItemDecoration(Utils.getApp()) {
    protected var color = 0

    //是否绘制第一条分割线
    var isDrawFirstDivider = true

    //列表方向为竖直方向
    var isVerticalOrientation = true

    init {
        this.color = color.toColor()
    }

    override fun getDivider(itemPosition: Int): Y_Divider? {
        val width = if (itemPosition == 0 && !isDrawFirstDivider) 0f else widthDp
        return Y_DividerBuilder()
            .apply {
                if (isVerticalOrientation) {
                    setBottomSideLine(true, color, width, 0f, 0f)
                } else {
                    setRightSideLine(true, color, width, 0f, 0f)
                }
            }
            .create()
    }
}